/**
 * Created by yan_my on 2016/10/30.
 */
import javax.imageio.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.File;

public class cutImage {
    private String srcpath;
    private String newpath;
    private BufferedImage originimage;
    private BufferedImage newimage;
    private int width;
    private int height;
    private int[] imageArray;

    public cutImage(String srcpath,String newpath)
    {
        this.srcpath=srcpath;
        this.newpath=newpath;
        try{
            this.originimage=ImageIO.read(new File(srcpath));
        }catch (IOException e){
            e.printStackTrace();
        }
        this.width=originimage.getWidth();
        this.height=originimage.getHeight();
        this.imageArray=new int[width*height];
    }

    public void cut(int x,int y)
    {
        try
        {
            originimage=ImageIO.read(new File(srcpath));
            originimage.getRGB(0,0,width,height,imageArray,0,width);
            newimage=new BufferedImage(x,y,BufferedImage.TYPE_INT_RGB);
            newimage.setRGB(0,0,x,y,imageArray,0,width);
            File outfile=new File(newpath);
            ImageIO.write(newimage,"jpg",outfile);
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
